import request from '@/router/axios'
import qs from 'qs'

// 获取产品信息列表
export const getList = () =>
  request({
    url: '/admin/sysProduct/list',
    method: 'get'
  })

// 查询
export const search = (id) =>
  request({
    url: `/admin/sysProduct/getById?id=${id}`,
    method: 'get'
  })

// 修改
export const update = (data) =>
  request({
    url: '/admin/sysProduct/save',
    method: 'post',
    data
  })

// 删除
export const del = (id) =>
  request({
    url: '/admin/sysProduct/del',
    method: 'DELETE',
    data: {
      id
    }
  })

//  产品域名
export const urlList = () =>
  request({
    url: '/admin/sysProductItem/list',
    method: 'get'
  })

//  修改或添加产品域名
export const urlSave = (data) =>
  request({
    url: '/admin/sysProductItem/save',
    method: 'post',
    data
  })

//  产品租户
export const tenantList = () =>
  request({
    url: `/admin/tenant/list`,
    method: 'get'
  })

//  已选租户
export const tenantChooseList = (productId) =>
  request({
    url: `/admin/sysProductTenant/list?productId=${productId}`,
    method: 'get'
  })

//  已选租户
export const tenantSave = (productId, tenderId) =>
  request({
    url: `/admin/sysProductTenant/saveAll?tenderId=${tenderId}`,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    method: 'post',
    data: qs.stringify({
      productId
    })
  })

//  获取权限
export const menuGet = (productId) =>
  request({
    url: `/admin/sysProduct/menu/${productId}`,
    method: 'get'
  })

//  保存权限
export const menuSave = (productId, menuIds) =>
  request({
    url: `/admin/sysProduct/menu`,
    method: 'put',
    params: {
      productId,
      menuIds
    }
  })

